USE [NGroup_VTL_DB]
GO

/****** Object:  StoredProcedure [dbo].[CheckUniqueString]    Script Date: 1/12/2014 5:01:55 PM ******/
DROP PROCEDURE [dbo].[CheckUniqueString]
GO

/****** Object:  StoredProcedure [dbo].[CheckUniqueString]    Script Date: 1/12/2014 5:01:55 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


-- =============================================
-- Author:		Bui Thanh Nam
-- Create date: 20131229
-- Description:	Check if unique string is existing
-- =============================================
CREATE PROCEDURE [dbo].[CheckUniqueString]
	@TypeID			INT,
	@UniqueString	NVARCHAR(500),
	@IsExisting		BIT OUTPUT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

	IF(@TypeID <> 4)
	BEGIN
		IF NOT EXISTS(
						SELECT * 
						FROM [dbo].[Products] WITH (NOLOCK) 
						WHERE [UniqueString] = @UniqueString
							  AND [IsActive] <> 0)
		BEGIN
			SELECT @IsExisting = 0
		END	
		ELSE
		BEGIN
			SELECT @IsExisting = 1
		END
	END
	ELSE
	BEGIN
		IF NOT EXISTS(
						SELECT * 
						FROM [dbo].[News] WITH (NOLOCK) 
						WHERE [UniqueString] = @UniqueString
							  AND [IsActive] <> 0)
		BEGIN
			SELECT @IsExisting = 0
		END	
		ELSE
		BEGIN
			SELECT @IsExisting = 1
		END
	END

    
END







GO


